﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using System.Reflection;

//分开不同的命名空间,不要放在一起,
//比如转换类的
namespace Tools
{
    public partial class Tool
    {

        //原机票系统.判断是否有效的空闲段.
        //总号段和使用的号段是放在一起的.
        public bool isExitsFreeSegment(Int64 startNo, Int64 endNo)
        {
            DataSet ds = getFreeJourneySegment(270);
            ArrayList arSegment = new ArrayList();
            ArrayList arEndNum = new ArrayList();


            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                double TempStartNo = Convert.ToDouble(dr["BeginNo"].ToString()) - 0.1;
                double TempEndNo = Convert.ToDouble(dr["EndNo"].ToString()) + 0.1;
                arSegment.Add(TempStartNo.ToString());
                arSegment.Add(TempEndNo.ToString());
                //arEndNum.Add(dr["EndNo"]);
                //总号往外扩展．小的减一，大的加一．
            }
            foreach (DataRow dr in ds.Tables[1].Rows)
            {
                //Int64 TempEndNo = Convert.ToInt64(dr["EndNo"].ToString());
                arSegment.Add(dr["BeginNo"]);
                arSegment.Add(dr["EndNo"]);
                //arSegment.Add((TempEndNo + 1).ToString());//此处不用加一了．
            }
            arSegment.Sort();

            for (int i = 0; i < arSegment.Count; i = i + 2)
            {
                double tempStartNo = Convert.ToDouble(arSegment[i].ToString());
                double tempEndNo = Convert.ToDouble(arSegment[i + 1].ToString());
                if (startNo > tempStartNo && endNo < tempEndNo)//　直接改为大于和小于．不要等于．
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 获取空闲的行程单号段
        /// </summary>
        /// <returns></returns>
        public DataSet getFreeJourneySegment(int CompID)
        {
            try
            {
                //SqlParameter[] parm ={
                //                        vsHelper.MakeInParam("@CompID",SqlDbType.Int,4,CompID)
                //                    };
                //DataSet ds = vsHelper.ExecProcDataSet("PR_getFreeJourneySegment", parm);
                return new DataSet();
            }
            catch (Exception)
            {
                return null;
            }

        }


        #region CopyModel
        public static void CopyModel<T1, T2>(T1 t1, T2 t2)
        {
            foreach (PropertyInfo pInfo in t1.GetType().GetProperties())
            {
                try
                {
                    object val = pInfo.GetValue(t1, null);
                    PropertyInfo info2 = getPropertyInfo<T2>(t2, pInfo.Name);
                    info2.SetValue(t2, val, null);
                }
                catch (Exception)
                {
                }
            }
        }

        private static PropertyInfo getPropertyInfo<T>(T t, string name)
        {
            foreach (PropertyInfo pInfo in t.GetType().GetProperties())
            {
                if (pInfo.Name == name)
                {
                    return pInfo;
                }
            }
            return null;
        }
        #endregion

    }
}
